package com.ghy.text;
import com.ghy.entity.EbOrderDetail;
import com.ghy.mapper.OrderDetailMapper;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import java.math.BigDecimal;
import java.util.List;
// 导入 spring 的单元测试
@RunWith(SpringJUnit4ClassRunner.class)
// 导入 spring 的配置文件
@ContextConfiguration("classpath:xml/spring-web.xml")
public class OrderDetailTest {
    @Autowired
    OrderDetailMapper orderdetailMapper;

    @Test
    public void testOrderDetailPage() {
        int page = 1;// 查询第 1 页
        int pageSize = 3;// 每页 3 条
//alt+Enter
        List<EbOrderDetail> orderdetail = orderdetailMapper.findByPage((page - 1) * pageSize, pageSize);
        System.out.println(orderdetail);
    }

    @Test
    public void testSave() {
        EbOrderDetail ebOrderDetail = new EbOrderDetail();
        ebOrderDetail.setEoId(8);
        ebOrderDetail.setEpId(7);
        ebOrderDetail.setEodQuantity(6);
        ebOrderDetail.setEodCost(new BigDecimal(5));

        int num = orderdetailMapper.save(ebOrderDetail);
        System.out.println(num);

    }
    @Test
    public void testOrderDetailDelete() {
        int result = orderdetailMapper.remove(1);
        System.out.println("result:" + result);
    }

    @Test
    public void testOrderDetailUpdate(){
        EbOrderDetail enOrderDetail = new EbOrderDetail();
        enOrderDetail.setEodId(9);
        enOrderDetail.setEoId(1);
        enOrderDetail.setEpId(1);
        enOrderDetail.setEodQuantity(1);
        enOrderDetail.setEodCost(new BigDecimal(11.11));
        //调用更新的方法
        int result = orderdetailMapper.updateByPrimaryKey(enOrderDetail);
        System.out.println("result:"+result);

    }

}
